#!/usr/bin/env python3

import timeit

"""
lin-algebra-lib test. Is rolling mergeMatrices() into a class_Matrix 
method a good idea in terms of performance? If class_Matrix changes 

Code snippets can be printed out by using print(testcode_a) and 
print(testcode_b)
"""


testcode_small_a="""
class class_Matrixa():
	isSanitized=False
	isTrimmed=False
	trimmedMode=""
	rows=0
	cols=0
	type="__Matrix__"
	def __init__(self, matrix_prototype):
		self.rows=len(matrix_prototype)
		self.cols=len(matrix_prototype[0])
		self.data=matrix_prototype
		return None

for i in range(0,10000):
	b=class_Matrixa([[6,4,3.0,6,3],[4,4,1,4,2],[6,9,4,5,2],[6,9,23,4,4],[3,3,4,5,6]])
	del b"""

testcode_small_b="""
class class_Matrixb():
	isSanitized=False
	isTrimmed=False
	trimmedMode=""
	rows=0
	cols=0
	type="__Matrix__"
	def __init__(self, matrix_prototype):
		self.rows=len(matrix_prototype)
		self.cols=len(matrix_prototype[0])
		self.data=matrix_prototype
		return None
	def appendHorizontal(self, matrixObject):
		if matrixObject.type!="__Matrix__":
			raise TypeError("Input variable is not a Matrix object.")
		if self.cols!=matrixObject.cols:
			raise ShapeError("Input Matrix object does not have the same amount of columns ("+str(self.cols)+"to"+str(matrixObject.cols)+").")
		for i in range(0, self.cols):
			self.data[i].append(matrixObject[i])
		return None
	def appendVertical(self, matrixObject):
		if matrixObject.type!="__Matrix__":
			raise TypeError("Input variable is not a Matrix object.")
		if self.rows!=matrixObject.rows:
			raise ShapeError("Input Matrix object does not have the same amount of rows ("+str(self.rows)+"to"+str(matrixObject.rows)+").")
		self.data.append(matrixObject.data)
		return None

for i in range(0,10000):
	b=class_Matrixb([[6,4,3.0,6,3],[4,4,1,4,2],[6,9,4,5,2],[6,9,23,4,4],[3,3,4,5,6]])
	del b"""

"""#Test for small matrices
print(timeit.timeit(stmt=testcode_small_a, number=1000))
print(timeit.timeit(stmt=testcode_small_b, number=1000))
#"""#Indistinguishable.


testcode_large_a="""
class class_Matrixa():
	isSanitized=False
	isTrimmed=False
	trimmedMode=""
	rows=0
	cols=0
	type="__Matrix__"
	def __init__(self, matrix_prototype):
		self.rows=len(matrix_prototype)
		self.cols=len(matrix_prototype[0])
		self.data=matrix_prototype
		return None

a=[0.0]*100000
c=[a]*100000

for i in range(0,10000000):
	b=class_Matrixa(c)
	del b"""

testcode_large_b="""
class class_Matrixb():
	isSanitized=False
	isTrimmed=False
	trimmedMode=""
	rows=0
	cols=0
	type="__Matrix__"
	def __init__(self, matrix_prototype):
		self.rows=len(matrix_prototype)
		self.cols=len(matrix_prototype[0])
		self.data=matrix_prototype
		return None
	def appendHorizontal(self, matrixObject):
		if matrixObject.type!="__Matrix__":
			raise TypeError("Input variable is not a Matrix object.")
		if self.cols!=matrixObject.cols:
			raise ShapeError("Input Matrix object does not have the same amount of columns ("+str(self.cols)+"to"+str(matrixObject.cols)+").")
		for i in range(0, self.cols):
			self.data[i].append(matrixObject[i])
		return None
	def appendVertical(self, matrixObject):
		if matrixObject.type!="__Matrix__":
			raise TypeError("Input variable is not a Matrix object.")
		if self.rows!=matrixObject.rows:
			raise ShapeError("Input Matrix object does not have the same amount of rows ("+str(self.rows)+"to"+str(matrixObject.rows)+").")
		self.data.append(matrixObject.data)
		return None

a=[0.0]*100000
c=[a]*100000

for i in range(0,10000000):
	b=class_Matrixb(c)
	del b"""

"""#Test for small matrices
print(timeit.timeit(stmt=testcode_large_a, number=1))
print(timeit.timeit(stmt=testcode_large_b, number=1))
#"""#Indistinguishable.


conclusion="""Adding the new methods apparently adds more cycles, and 
therefore takes more time. However, the differences are negligible, to 
the point that the noise from execution to execution """
